home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1996 #6 / Amiga Plus CD - 1996 - No. 06.iso / pd / tools / pc-heiniv0.56 / source / mainwindow.h < prev    next >
C/C++ Source or Header  |  1996-08-02  |  9KB  |  235 lines

  1. /*
  2. **
  3. **    mainwindow.h  Release 1
  4. **
  5. **    Mainwin Class
  6. **    derived from MUIC_Window
  7. **    controlls inputevents, opens menus
  8. **    and a Popgroup Object
  9. **    includes About- and AboutMUI-Requesters
  10. **
  11. **    ©1996 Ctryxx/Trinomic (Stephan Quitzsch)
  12. **
  13. */
  14.  
  15.  
  16. #define Mainwin_Base 0x2                // first digit
  17.  
  18. #define MUIM_Mainwin_About 0x222
  19. #define MUIM_Mainwin_Abmui 0x223
  20. #define MUIM_Mainwin_Close 0x224
  21. #define MUIM_Mainwin_Quit  0x225
  22. #define MUIM_Mainwin_New   0x226
  23.  
  24. #define CNT_MAXWIN    10                // never > 0xFF !!!
  25.  
  26. /*============================================================================*/
  27.  
  28. struct MUI_CustomClass *CL_Mainwin;
  29.  
  30. /*============================================================================*/
  31.  
  32. struct MUIP_Mainwin_Test { ULONG MethodID; int count; };
  33. static char wndcnt = 0;                // counts open mainwindows
  34.  
  35. /*============================================================================*/
  36. /*= Mainwin class                                                            =*/
  37. /*============================================================================*/
  38.  
  39. struct Mainwin_Data
  40. {
  41.     APTR mui_popgroup;                // Objects
  42.     APTR mui_about;
  43.     APTR mui_muiab;
  44.     APTR mui_new;
  45.     APTR mui_open;
  46.     APTR mui_prt;
  47.     APTR mui_quit;
  48.     APTR mui_seek;
  49.     APTR mui_fwd;
  50.     APTR mui_bwd;
  51. };
  52.  
  53. /*============================================================================*/
  54.  
  55. ULONG Mainwin_Close( struct IClass *cl, Object *obj, Msg msg )        // Close Window
  56. {
  57.     set( obj, MUIA_Window_Open, FALSE );
  58.     wndcnt--;
  59.  
  60.     if( wndcnt == 0 )
  61.     {
  62.         DoMethod( xget(obj, MUIA_ApplicationObject), MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit );
  63.         return (ULONG)obj;
  64.     }
  65.  
  66.     DoMethod( xget(obj, MUIA_ApplicationObject), OM_REMMEMBER, obj );
  67.     MUI_DisposeObject( obj );                                // kill Window Object
  68.  
  69.     return 0l;
  70. }
  71.  
  72.  
  73. ULONG Mainwin_Quit( struct IClass *cl, Object *obj, Msg msg )        // Quit whole Application
  74. {
  75.     DoMethod( xget(obj, MUIA_ApplicationObject), MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit );
  76.     return (ULONG)obj;
  77. }
  78.  
  79.  
  80. ULONG Mainwin_About( struct IClass *cl, Object *obj, Msg msg )        // About PC-Heini
  81. {
  82.     MUI_RequestA( (APTR)xget(obj, MUIA_ApplicationObject), 0l, 0l, PCH_VERS, "Oki", "PC-Heini\nby Ctryxx/Trinomic 1995-96\nwir95ccv@manitu.rz.uni-leipzig.de", 0 );
  83.     return 0l;
  84. }
  85.  
  86.  
  87. ULONG Mainwin_Newwin( struct IClass *cl, Object *obj, Msg msg )        // New Window
  88. {
  89.     APTR mui_nwin;
  90.     LONG app = xget( obj, MUIA_ApplicationObject );
  91.  
  92.     if( wndcnt > CNT_MAXWIN )
  93.     {
  94.         MUI_RequestA( 0l, 0l, 0l, "PC-Heini message", "Grumpf!", "I think, it's enough, isn't it?", 0 );
  95.         return 0l;
  96.     }
  97.  
  98.     mui_nwin = NewObject( CL_Mainwin->mcc_Class, NULL, TAG_DONE );
  99.  
  100.     if( mui_nwin )
  101.     {
  102.         DoMethod( app, OM_ADDMEMBER, mui_nwin );
  103.         set( mui_nwin, MUIA_Window_Open, TRUE );
  104.     }
  105.     else MUI_RequestA( 0l, 0l, 0l, "An Error came up!", "Ok|Cancel", "Can't open window!", 0 );
  106.  
  107.     return 0l;
  108. }
  109.  
  110.  
  111. ULONG Mainwin_Abmui( struct IClass *cl, Object *obj, Msg msg )        // About MUI
  112. {
  113.     static APTR mui_awin = 0l;
  114.  
  115.     if( !mui_awin )
  116.     {    mui_awin = AboutmuiObject, MUIA_Aboutmui_Application, xget( obj, MUIA_ApplicationObject ), End;
  117.     }
  118.     if( mui_awin ) set( mui_awin, MUIA_Window_Open, TRUE );
  119.  
  120.     return 0l;
  121. }
  122.  
  123.  
  124. ULONG Mainwin_New( struct IClass *cl, Object *obj, Msg msg )
  125. {
  126.     APTR mui_pgrp;                                            // Objects
  127.     APTR mui_new;
  128.     APTR mui_open;
  129.     APTR mui_prt;
  130.     APTR mui_about;
  131.     APTR mui_muiab;
  132.     APTR mui_quit;
  133.     APTR mui_seek;
  134.     APTR mui_fwd;
  135.     APTR mui_bwd;
  136.  
  137.     struct Mainwin_Data *data;
  138.  
  139.  
  140.     obj = (Object*) DoSuperNew( cl, obj,
  141.         MUIA_Window_ID, 0x50434800+wndcnt,
  142.         MUIA_Window_AppWindow, TRUE,
  143.         MUIA_Window_Title, "PC-Heini by Ctryxx", 
  144.         MUIA_Window_Height, MUIV_Window_Height_Screen(100),
  145.         MUIA_Window_Width, MUIV_Window_Width_Screen(100),
  146.  
  147.         MUIA_Window_Menustrip, MenustripObject,
  148.             MUIA_Family_Child, MenuObject,
  149.                 MUIA_Menu_Title, "Project",
  150.                 MUIA_Family_Child, mui_new = MenuitemObject, MUIA_Menuitem_Title, "New", MUIA_Menuitem_Shortcut, "N", End,
  151.                 MUIA_Family_Child, mui_open = MenuitemObject, MUIA_Menuitem_Title, "Open", MUIA_Menuitem_Shortcut, "O", End,
  152.                 MUIA_Family_Child, mui_prt = MenuitemObject, MUIA_Menuitem_Title, "Print", MUIA_Menuitem_Shortcut, "P", End,
  153.                 MUIA_Family_Child, mui_about = MenuitemObject, MUIA_Menuitem_Title, "About PC-Heini", MUIA_Menuitem_Shortcut, "A", End,
  154.                 MUIA_Family_Child, mui_muiab = MenuitemObject, MUIA_Menuitem_Title, "About MUI", MUIA_Menuitem_Shortcut, "M", End,
  155.                 MUIA_Family_Child, mui_quit = MenuitemObject, MUIA_Menuitem_Title, "Quit", MUIA_Menuitem_Shortcut, "Q", End,
  156.             End,
  157.             MUIA_Family_Child, MenuObject,
  158.                 MUIA_Menu_Title, "Search",
  159.                 MUIA_Family_Child, mui_seek = MenuitemObject, MUIA_Menuitem_Title, "Search", MUIA_Menuitem_Shortcut, "S", End,
  160.                 MUIA_Family_Child, mui_fwd = MenuitemObject, MUIA_Menuitem_Title, "Search forward", MUIA_Menuitem_Shortcut, "F", End,
  161.                 MUIA_Family_Child, mui_bwd = MenuitemObject, MUIA_Menuitem_Title, "Search backward", MUIA_Menuitem_Shortcut, "B", End,
  162.             End,
  163.         End,
  164.  
  165.             WindowContents, VGroup,
  166.                 Child, mui_pgrp = NewObject( CL_Popgroup->mcc_Class, NULL, TAG_DONE ),
  167.         End,
  168.     TAG_DONE
  169.     );
  170.  
  171.     if( obj ) wndcnt++;
  172.  
  173.     data = INST_DATA( cl, obj );                                // make Objects private
  174.     data->mui_popgroup = mui_pgrp;
  175.     data->mui_new   = mui_new;
  176.     data->mui_open  = mui_open;
  177.     data->mui_prt   = mui_prt;
  178.     data->mui_quit  = mui_quit;
  179.     data->mui_about = mui_about;
  180.     data->mui_muiab = mui_muiab;
  181.     data->mui_seek  = mui_seek;
  182.     data->mui_fwd   = mui_fwd;
  183.     data->mui_bwd   = mui_bwd;
  184.  
  185.     DoMethod( obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, obj, 1, MUIM_Mainwin_Close );
  186.     DoMethod( obj, MUIM_Notify, MUIA_Window_InputEvent, "p", data->mui_popgroup, 2, MUIM_Popgroup_Pop, "t" );
  187.  
  188.     DoMethod( obj, MUIM_Notify, MUIA_Window_InputEvent, "-repeat Up", data->mui_popgroup, 1, MUIM_Textwd_Up );
  189.     DoMethod( obj, MUIM_Notify, MUIA_Window_InputEvent, "-repeat Down", data->mui_popgroup, 1, MUIM_Textwd_Down );
  190.     DoMethod( obj, MUIM_Notify, MUIA_Window_InputEvent, "-repeat shift up", data->mui_popgroup, 1, MUIM_Textwd_Back );
  191.     DoMethod( obj, MUIM_Notify, MUIA_Window_InputEvent, "-repeat shift down", data->mui_popgroup, 1, MUIM_Textwd_Next );
  192.     DoMethod( obj, MUIM_Notify, MUIA_Window_InputEvent, "-repeat Left", data->mui_popgroup, 1, MUIM_Textwd_Back );
  193.     DoMethod( obj, MUIM_Notify, MUIA_Window_InputEvent, "-repeat Right", data->mui_popgroup, 1, MUIM_Textwd_Next );
  194.     DoMethod( obj, MUIM_Notify, MUIA_Window_InputEvent, "s", data->mui_popgroup, 1, MUIM_Popgroup_Gname );
  195.     DoMethod( obj, MUIM_Notify, MUIA_Window_InputEvent, "f", data->mui_popgroup, 1, MUIM_Textwd_Nsk );
  196.     DoMethod( obj, MUIM_Notify, MUIA_Window_InputEvent, "b", data->mui_popgroup, 1, MUIM_Textwd_Bsk );
  197.  
  198.     DoMethod( data->mui_about, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, obj, 1, MUIM_Mainwin_About );
  199.     DoMethod( data->mui_muiab, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, obj, 1, MUIM_Mainwin_Abmui );
  200.     DoMethod( data->mui_new, MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, obj, 1, MUIM_Mainwin_New );
  201.     DoMethod( data->mui_open,  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, data->mui_popgroup, 1, MUIM_Popgroup_Freq );
  202.     DoMethod( data->mui_prt,  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, data->mui_popgroup, 1, MUIM_Textwd_Prt );
  203.     DoMethod( data->mui_quit,  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, obj, 1, MUIM_Mainwin_Quit );
  204.     DoMethod( data->mui_seek,  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, data->mui_popgroup, 1, MUIM_Popgroup_Gname );
  205.     DoMethod( data->mui_fwd,  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, data->mui_popgroup, 1, MUIM_Textwd_Nsk );
  206.     DoMethod( data->mui_bwd,  MUIM_Notify, MUIA_Menuitem_Trigger, MUIV_EveryTime, data->mui_popgroup, 1, MUIM_Textwd_Bsk );
  207.  
  208.     return (ULONG)obj;
  209. }
  210.  
  211.  
  212. __saveds __asm ULONG Mainwin_Dispatcher( register __a0 struct IClass *cl, register __a2 Object *obj, register __a1 Msg msg )
  213. {    struct Mainwin_Data *data = INST_DATA( cl, obj );
  214.  
  215.     switch (msg->MethodID)
  216.     {
  217.         case OM_NEW:            return Mainwin_New   ( cl, obj, (APTR)msg );
  218.         case MUIM_Mainwin_Quit :    return Mainwin_Quit  ( cl, obj, (APTR)msg );
  219.         case MUIM_Mainwin_About:    return Mainwin_About ( cl, obj, (APTR)msg );
  220.         case MUIM_Mainwin_Abmui:    return Mainwin_Abmui ( cl, obj, (APTR)msg );
  221.         case MUIM_Mainwin_Close:    return Mainwin_Close ( cl, obj, (APTR)msg );
  222.         case MUIM_Mainwin_New  :    return Mainwin_Newwin( cl, obj, (APTR)msg );
  223.     }
  224.  
  225.     if( (msg->MethodID)>>8 == Textwd_Base )                        // If Message for Textwd-Class...
  226.     {    return (ULONG)DoSuperMethodA( CL_Popgroup, data->mui_popgroup, msg );
  227.     }
  228.  
  229.     if( (msg->MethodID)>>8 == Popgroup_Base )                    // If Message for Popgroup-Class...
  230.     {    return (ULONG)DoSuperMethodA( CL_Popgroup, data->mui_popgroup, msg );
  231.     }
  232.  
  233.     return (ULONG)DoSuperMethodA( cl, obj, msg );
  234. }
  235.